﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Media;
using System.IO;
using System.Runtime.InteropServices;

namespace WindowsFormsApplication1
{
    public partial class Burn : Form
    {
        ArrayList imageList;
        Form1 theForm1;

        public Burn(Form1 aForm1, ArrayList aL)
        {
            this.CenterToParent();
            InitializeComponent();
            imageList = aL;
            theForm1 = aForm1;
            ProcessCDTray(true);
            listView1.TileSize = new System.Drawing.Size(100, 80);
            this.listView1.View = View.LargeIcon;
            this.listView1.LargeImageList = theForm1.imageList;
           

            int i = 0;

            ArrayList a = (ArrayList)imageList;

            foreach (object imageIndex in a)
            {
                listView1.Items.Add(theForm1.imageFileNameList[(int)imageIndex]);
                listView1.Items[i].ImageIndex = (int)imageIndex;
                i++;
                progressBar1.Value = i;
            }
       
   
        }
        //Win32 API Call
        [DllImport("winmm.dll", EntryPoint = "mciSendStringA", CharSet = CharSet.Ansi)]
        protected static extern int mciSendString(string lpstrCommand, StringBuilder lpstrReturnString, int uReturnLength, IntPtr hwndCallback);

        //Method
        #region Open/Close CD Tray
        ///
        /// method to open or close the CD tray based on the
        /// boolean value passed
        ///
        ///
        ///
        public bool ProcessCDTray(bool open)
        {
            int ret = 0;
            //do a switch of the value passed
            switch (open)
            {
                case true: //true = open the cd
                    ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);
                    return true;
                    break;
                case false: //false = close the tray
                    ret = mciSendString("set cdaudio door closed", null, 0, IntPtr.Zero);
                    return true;
                    break;
                default:
                    ret = mciSendString("set cdaudio door open", null, 0, IntPtr.Zero);
                    return true;
                    break;
            }
        }
        #endregion 


        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void textBox1_TextChanged(object sender, EventArgs e)
        {

        }

        private void button2_Click(object sender, EventArgs e)
        {


            Close();
        }

        private void button1_Click(object sender, EventArgs e)
        {
         //   autoComplete1.Text.
            if (textBox1.Text.Equals(""))
            {
                MessageBox.Show("Please Give a Name to the Disc");

            }
            else if(progressBar1.Value >100)
            {
                MessageBox.Show("You have too many photos\n Remove some of them to make it fit on the disc");
            }
            else
            {
                Burning burningForm = new Burning();
                burningForm.ShowDialog();
                Close();
            }
        }



        private void button3_Click(object sender, EventArgs e)
        {
            foreach (ListViewItem lvi in listView1.SelectedItems)
            {
                listView1.Items.Remove(lvi);
                listView1.Refresh();
                progressBar1.Value = progressBar1.Value - 1;
            }
        }
    }
}
